﻿<template>
	<div class="card-fill layout-padding" v-loading="loading" element-loading-text="Loading...">
		<WtmSearcher v-if="searchBar" v-model="searchData" @search="getTableData">
			<template #primary="{ showAdvanced }">
				<el-row :gutter="15">
					<!-- 常用搜索条件 -->
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<el-form-item ref="Name_FormItem" prop="Name">
							<template #label>
								<WtmLabelTooltip label="姓名" tooltip="员工姓名" />
							</template>
							<el-input v-model="searchData.Name" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<el-form-item ref="StaffNo_FormItem" prop="StaffNo">
							<template #label>
								<WtmLabelTooltip label="工号" tooltip="员工工号" />
							</template>
							<el-input v-model="searchData.StaffNo" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<el-form-item ref="State_FormItem" prop="State">
							<template #label>
								<WtmLabelTooltip label="人员状态" tooltip="人员状态" />
							</template>
							<el-select v-model="searchData.State" clearable>
								<el-option key="在职" value="在职" label="在职"></el-option>
								<el-option key="试用期" value="试用期" label="试用期"></el-option>
								<el-option key="离职" value="离职" label="离职"></el-option>
								<el-option key="退休" value="退休" label="退休"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<WtmOrgSelector v-model="searchData.OrgId" :clearable="true" :filterable="true" placeholder="请选择公司" label="公司" tooltip="公司" />
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<WtmDeptSelector
							v-model="searchData.GroupId"
							:clearable="true"
							:filterable="true"
							placeholder="请选择部门"
							label="部门"
							:rules="[]"
							:auth="false"
						/>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<el-form-item ref="Phone_FormItem" prop="Phone">
							<template #label>
								<WtmLabelTooltip label="手机号" tooltip="手机号" />
							</template>
							<el-input v-model="searchData.Phone" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
						<el-form-item ref="WorkflowStatus_FormItem" prop="WorkflowStatus">
							<template #label>
								<WtmLabelTooltip label="流程状态" tooltip="流程状态" />
							</template>
							<el-select v-model="searchData.WorkflowStatus" clearable>
								<el-option key="待提交" value="待提交" label="待提交"></el-option>
								<el-option key="提交中" value="提交中" label="提交中"></el-option>
								<el-option key="审核中" value="审核中" label="审核中"></el-option>
								<el-option key="已完成" value="已完成" label="已完成"></el-option>
								<el-option key="已取消" value="已取消" label="已取消"></el-option>
							</el-select>
						</el-form-item>
					</el-col>

					<!-- 可展开的详细搜索条件 -->
					<template v-if="showAdvanced">
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="BirthDate_FormItem" prop="BirthDate">
								<template #label>
									<WtmLabelTooltip label="出生日期" tooltip="出生日期" />
								</template>
								<el-date-picker type="daterange" v-model="searchData.BirthDate" clearable style="width: 100%"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="Gender_FormItem" prop="Gender">
								<template #label>
									<WtmLabelTooltip label="性别" tooltip="性别" />
								</template>
								<el-select v-model="searchData.Gender" clearable>
									<el-option key="男" value="男" label="男"></el-option>
									<el-option key="女" value="女" label="女"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="Ethnicity_FormItem" prop="Ethnicity">
								<template #label>
									<WtmLabelTooltip label="民族" tooltip="民族" />
								</template>
								<el-select v-model="searchData.Ethnicity" clearable>
									<el-option key="汉族" value="汉族" label="汉族"></el-option>
									<el-option key="回族" value="回族" label="回族"></el-option>
									<el-option key="满族" value="满族" label="满族"></el-option>
									<el-option key="蒙古族" value="蒙古族" label="蒙古族"></el-option>
									<el-option key="壮族" value="壮族" label="壮族"></el-option>
									<el-option key="其他" value="其他" label="其他"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="AgeRange_FormItem" prop="AgeRange">
								<template #label>
									<WtmLabelTooltip label="年龄范围" tooltip="年龄范围" />
								</template>
								<div class="range-input-container">
									<el-input-number
										v-model="searchData.AgeStart"
										:min="0"
										:max="150"
										controls-position="right"
										:controls="false"
										placeholder="起始"
										clearable
										class="range-input-start"
									></el-input-number>
									<span class="range-separator">至</span>
									<el-input-number
										v-model="searchData.AgeEnd"
										:min="0"
										:max="150"
										controls-position="right"
										:controls="false"
										placeholder="结束"
										clearable
										class="range-input-end"
									></el-input-number>
								</div>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="HighestEducation_FormItem" prop="HighestEducation">
								<template #label>
									<WtmLabelTooltip label="最高学历" tooltip="最高学历" />
								</template>
								<el-select v-model="searchData.HighestEducation" clearable>
									<el-option key="小学" value="小学" label="小学"></el-option>
									<el-option key="初中" value="初中" label="初中"></el-option>
									<el-option key="高中" value="高中" label="高中"></el-option>
									<el-option key="中专" value="中专" label="中专"></el-option>
									<el-option key="大专" value="大专" label="大专"></el-option>
									<el-option key="本科" value="本科" label="本科"></el-option>
									<el-option key="研究生" value="研究生" label="研究生"></el-option>
									<el-option key="硕士" value="硕士" label="硕士"></el-option>
									<el-option key="博士" value="博士" label="博士"></el-option>
									<el-option key="博士后" value="博士后" label="博士后"></el-option>
									<el-option key="博士研究生" value="博士研究生" label="博士研究生"></el-option>
									<el-option key="其他" value="其他" label="其他"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="MaritalStatus_FormItem" prop="MaritalStatus">
								<template #label>
									<WtmLabelTooltip label="婚姻状况" tooltip="婚姻状况" />
								</template>
								<el-select v-model="searchData.MaritalStatus" clearable>
									<el-option key="未婚" value="未婚" label="未婚"></el-option>
									<el-option key="已婚" value="已婚" label="已婚"></el-option>
									<el-option key="离异" value="离异" label="离异"></el-option>
									<el-option key="丧偶" value="丧偶" label="丧偶"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="IdCardNo_FormItem" prop="IdCardNo">
								<template #label>
									<WtmLabelTooltip label="身份证号" tooltip="身份证号码" />
								</template>
								<el-input v-model="searchData.IdCardNo" clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="IsVeteran_FormItem" prop="IsVeteran">
								<template #label>
									<WtmLabelTooltip label="是否退伍军人" tooltip="是否为退伍军人" />
								</template>
								<el-select v-model="searchData.IsVeteran" clearable>
									<el-option key="是" :value="true" label="是"></el-option>
									<el-option key="否" :value="false" label="否"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="PoliticalStatus_FormItem" prop="PoliticalStatus">
								<template #label>
									<WtmLabelTooltip label="政治面貌" tooltip="政治面貌" />
								</template>
								<el-select v-model="searchData.PoliticalStatus" clearable>
									<el-option key="中共党员" value="中共党员" label="中共党员"></el-option>
									<el-option key="共青团员" value="共青团员" label="共青团员"></el-option>
									<el-option key="群众" value="群众" label="群众"></el-option>
									<el-option key="无党派人士" value="无党派人士" label="无党派人士"></el-option>
									<el-option key="其他" value="其他" label="其他"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="WorkYearsRange_FormItem" prop="WorkYearsRange">
								<template #label>
									<WtmLabelTooltip label="工龄范围" tooltip="工龄范围" />
								</template>
								<div class="range-input-container">
									<el-input-number
										v-model="searchData.WorkYearsStart"
										:min="0"
										:max="50"
										:precision="1"
										:controls="false"
										placeholder="起始"
										clearable
										controls-position="right"
										class="range-input-start"
									></el-input-number>
									<span class="range-separator">至</span>
									<el-input-number
										v-model="searchData.WorkYearsEnd"
										:min="0"
										:max="50"
										:precision="1"
										:controls="false"
										placeholder="结束"
										clearable
										controls-position="right"
										class="range-input-end"
									></el-input-number>
								</div>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="CompanyYearsRange_FormItem" prop="CompanyYearsRange">
								<template #label>
									<WtmLabelTooltip label="司龄范围" tooltip="司龄范围" />
								</template>
								<div class="range-input-container">
									<el-input-number
										v-model="searchData.CompanyYearsStart"
										:min="0"
										:max="50"
										:precision="1"
										:controls="false"
										placeholder="起始"
										clearable
										controls-position="right"
										class="range-input-start"
									></el-input-number>
									<span class="range-separator">至</span>
									<el-input-number
										v-model="searchData.CompanyYearsEnd"
										:min="0"
										:max="50"
										:precision="1"
										:controls="false"
										placeholder="结束"
										clearable
										controls-position="right"
										class="range-input-end"
									></el-input-number>
								</div>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="BillCode_FormItem" prop="BillCode">
								<template #label>
									<WtmLabelTooltip label="单据编号" tooltip="单据编号" />
								</template>
								<el-input v-model="searchData.BillCode" clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="BillStatus_FormItem" prop="BillStatus">
								<template #label>
									<WtmLabelTooltip label="单据状态" tooltip="单据状态" />
								</template>
								<el-select v-model="searchData.BillStatus" clearable>
									<el-option key="草稿" value="草稿" label="草稿"></el-option>
									<el-option key="正文" value="正文" label="正文"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="Approver_FormItem" prop="Approver">
								<template #label>
									<WtmLabelTooltip label="审批人" tooltip="流程审批人" />
								</template>
								<el-input v-model="searchData.Approver" clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="ApprovalTime_FormItem" prop="ApprovalTime">
								<template #label>
									<WtmLabelTooltip label="审批时间" tooltip="流程审批时间" />
								</template>
								<el-date-picker type="daterange" v-model="searchData.ApprovalTime" clearable></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="ArchiveLocation_FormItem" prop="ArchiveLocation">
								<template #label>
									<WtmLabelTooltip label="档案所在地" tooltip="档案存放地" />
								</template>
								<el-input v-model="searchData.ArchiveLocation" clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15">
							<el-form-item ref="ArchiveNo_FormItem" prop="ArchiveNo">
								<template #label>
									<WtmLabelTooltip label="存档号" tooltip="档案编号" />
								</template>
								<el-input v-model="searchData.ArchiveNo" clearable></el-input>
							</el-form-item>
						</el-col>
					</template>
				</el-row>
			</template>
		</WtmSearcher>

		<div v-if="toolbar">
			<WtmButton
				v-auth="'/api/SysPersonRepairBill/Add'"
				icon="fa fa-plus"
				type="primary"
				:button-text="$t('message._system.common.vm.add')"
				@click="OnCreateClick()"
			/>
			<WtmButton
				v-auth="'/api/SysPersonRepairBill/BatchDelete'"
				icon="fa fa-trash"
				type="danger"
				:button-text="$t('message._system.common.vm.batchdelete')"
				:disabled="!hasSelectedRows"
				:confirm="$t('message._system.common.vm.deletetip')"
				@click="onBatchDelete()"
			/>
			<WtmButton
				v-auth="'/api/SysPersonRepairBill/UpdateWorkflowStatus'"
				icon="fa fa-refresh"
				type="primary"
				button-text="更新流程状态"
				:disabled="!hasSelectedRows"
				@click="onUpdateWorkflowStatus()"
			/>
			<WtmButton
				v-auth="'/api/SysPersonRepairBill/Import'"
				icon="fa fa-tasks"
				type="primary"
				:button-text="$t('message._system.common.vm.import')"
				@click="OnImportClick()"
			/>
			<WtmButton
				v-auth="'/api/SysPersonRepairBill/SysPersonRepairBillExportExcel'"
				icon="fa fa-arrow-circle-down"
				type="primary"
				:button-text="$t('message._system.common.vm.export')"
				@click="onExport()"
			/>
		</div>

		<WtmTable ref="tableRef" v-bind="tableData" class="table-operation-area">
			<template #operation>
				<el-table-column :label="$t('message._system.common.vm.operate')" min-width="180" align="center" class-name="operation-column">
					<template v-slot="scope">
						<div class="operation-container">
							<WtmButton
								v-auth="'/api/SysPersonRepairBill/Edit'"
								v-if="scope.row.BillStatus === '草稿'"
								:is-text="true"
								icon="fa fa-pencil-square"
								type="warning"
								:button-text="$t('message._system.common.vm.edit')"
								@click="OnEditRowClick(scope.row)"
							/>
							<WtmButton
								v-if="scope.row.CanApprove == true"
								:is-text="true"
								icon="fa fa-check"
								type="primary"
								button-text="审批"
								@click="OnDetailsRowClick(scope.row)"
							/>
							<WtmButton
								v-else
								v-auth="'/api/SysPersonRepairBill/{id}'"
								:is-text="true"
								icon="fa fa-info-circle"
								type="info"
								:button-text="$t('message._system.common.vm.detail')"
								@click="OnDetailsRowClick(scope.row)"
							/>
							<WtmButton
								v-auth="'/api/SysPersonRepairBill/BatchDelete'"
								v-if="scope.row.BillStatus === '草稿'"
								icon="fa fa-trash"
								type="danger"
								:button-text="$t('message._system.common.vm.delete')"
								:confirm="$t('message._system.common.vm.deletetip')"
								:is-text="true"
								@click="onDelete(scope.row)"
							/>
						</div>
					</template>
				</el-table-column>
			</template>
		</WtmTable>
	</div>
</template>

<script setup lang="ts" name="员工档案补录;true;HengTong.Areas.Person.Controllers;SysPersonRepairBill">
import ElMessage from 'element-plus/es/components/message/index';
import { defineAsyncComponent, ref, getCurrentInstance, onMounted, computed } from 'vue';
import { SysPersonRepairBillApi as api } from '/@/views/person/syspersonrepairbill/api';
import { ISysPersonRepairBillView, ISysPersonRepairBillQuery } from '/@/views/person/syspersonrepairbill/api/interface';
import other from '/@/utils/other';
import commonFunction from '/@/utils/commonFunction';

const ci = getCurrentInstance() as any;
const { dateFormatYMD } = commonFunction();
const loading = ref(false);
const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const props = withDefaults(
	defineProps<{
		/** 是否显示搜索(筛选)栏 */
		searchBar?: boolean;
		/** 是否显示工具栏 */
		toolbar?: boolean;
		/** 是否禁用表格任何操作 */
		isDisabled?: boolean;
		/** 默认筛选 */
		filters?: ISysPersonRepairBillQuery;
		/** 主表ID */
		entityId?: string | null;
	}>(),
	{
		searchBar: true,
		toolbar: true,
		isDisabled: true,
		filters: () => ({}),
		entityId: null,
	}
);

const searchData = ref<ISysPersonRepairBillQuery>({});

// 定义变量内容
const tableRef = ref();
const tableData = ref({
	// 列表数据（必传）
	data: [],
	// 表头内容（必传，注意格式）
	header: [
		{ title: '单据编号', key: 'BillCode', type: 'text', isCheck: true, width: '110px' },
		{ title: '单据状态', key: 'BillStatus', type: 'text', isCheck: true },
		{
			title: '流程状态',
			key: 'WorkflowStatus',
			type: 'tag',
			isCheck: true,
			tagType: (row: ISysPersonRepairBillView) => {
				const statusMap: Record<string, string> = {
					待提交: 'info',
					提交中: 'info',
					审核中: 'warning',
					已完成: 'success',
					已取消: 'danger',
				};
				return statusMap[row.WorkflowStatus || ''] || 'info';
			},
		},
		{ title: '备注', key: 'Remark', type: 'text', isCheck: true },
		{ title: '审批人', key: 'Approver', type: 'text', isCheck: true },
		{ title: '审批时间', key: 'ApprovalTime', type: 'text', isCheck: true },
		{ title: '姓名', key: 'Name', type: 'text', isCheck: true },
		{ title: '工号', key: 'StaffNo', type: 'text', isCheck: true },
		{ title: '工龄', key: 'WorkYears', type: 'text', isCheck: true },
		{ title: '司龄', key: 'CompanyYears', type: 'text', isCheck: true },
		{
			title: '出生日期',
			key: 'BirthDate',
			type: 'text',
			isCheck: true,
			formatter: (row: ISysPersonRepairBillView, value: any) => dateFormatYMD(row as any, 0 as any, value),
		},
		{ title: '年龄', key: 'Age', type: 'text', isCheck: true },
		{ title: '性别', key: 'Gender', type: 'text', isCheck: true },
		{ title: '民族', key: 'Ethnicity', type: 'text', isCheck: true },
		{ title: '学历', key: 'HighestEducation', type: 'text', isCheck: true },
		{ title: '婚否', key: 'MaritalStatus', type: 'text', isCheck: true },
		{ title: '退伍', key: 'IsVeteran', type: 'text', isCheck: true },
		{ title: '照片', key: 'PhotoId', type: 'image', isCheck: true },
		{ title: '身份证号', key: 'IdCardNo', type: 'text', isCheck: true },
		{ title: '身份证人像面', key: 'IdCardFrontPhotoId', type: 'image', isCheck: true },
		{ title: '身份证国徽面', key: 'IdCardBackPhotoId', type: 'image', isCheck: true },
		{ title: '户籍地', key: 'HouseholdRegistration', type: 'text', isCheck: true },
		{ title: '籍贯', key: 'NativePlace', type: 'text', isCheck: true },
		{ title: '政治', key: 'PoliticalStatus', type: 'text', isCheck: true },
		{ title: '入党日期', key: 'PartyJoinDate', type: 'text', isCheck: true },
		{ title: '支部', key: 'PartyBranch', type: 'text', isCheck: true },
		{ title: '档案所在地', key: 'ArchiveLocation', type: 'text', isCheck: true },
		{ title: '存档号', key: 'ArchiveNo', type: 'text', isCheck: true },
		{ title: '档案调出', key: 'ArchiveTransferOutDate', type: 'text', isCheck: true },
		{ title: '档案调入', key: 'ArchiveTransferInDate', type: 'text', isCheck: true },
		{ title: '家庭住址', key: 'HomeAddress', type: 'text', isCheck: true },
		{ title: '手机号', key: 'Phone', type: 'text', isCheck: true },
		{ title: '邮箱', key: 'Email', type: 'text', isCheck: true },
		{ title: '工资卡', key: 'SalaryBank', type: 'text', isCheck: true },
		{ title: '工资卡号', key: 'SalaryAccount', type: 'text', isCheck: true },
		{ title: '奖金卡', key: 'BonusBank', type: 'text', isCheck: true },
		{ title: '奖金卡号', key: 'BonusAccount', type: 'text', isCheck: true },
		{ title: '公司', key: 'OrgName', type: 'text', isCheck: true },
		{ title: '部门', key: 'GroupName', type: 'text', isCheck: true },
		{ title: '岗位', key: 'JobPositionName', type: 'text', isCheck: true },
		{ title: '简历', key: 'ResumeId', type: 'text', isCheck: true },
		{ title: '入职日期', key: 'HireDate', type: 'text', isCheck: true },
		{ title: '转正日期', key: 'ConfirmationDate', type: 'text', isCheck: true },
		{ title: '用工形式', key: 'EmploymentType', type: 'text', isCheck: true },
		{ title: '合同类型', key: 'ContractType', type: 'text', isCheck: true },
		{ title: '合同编号', key: 'ContractNo', type: 'text', isCheck: true },
		{ title: '合同起始', key: 'ContractStartDate', type: 'text', isCheck: true },
		{ title: '合同终止', key: 'ContractEndDate', type: 'text', isCheck: true },
		{ title: '离职日期', key: 'ResignationDate', type: 'text', isCheck: true },
		{ title: '离职原因', key: 'ResignationReason', type: 'text', isCheck: true },
		{ title: '离职类型', key: 'ResignationType', type: 'text', isCheck: true },
		{ title: '状态', key: 'State', type: 'text', isCheck: true },
		{ title: '血型', key: 'BloodType', type: 'text', isCheck: true },
		{ title: '爱好特长', key: 'Hobbies', type: 'text', isCheck: true },
		{ title: '教育经历', key: 'PersonEducationsName', type: 'text', isCheck: true },
		{ title: '家庭成员', key: 'PersonFamiliesName', type: 'text', isCheck: true },
		{ title: '工作经历', key: 'PersonWorksName', type: 'text', isCheck: true },
		{ title: '培训经历', key: 'PersonTrainExamsName', type: 'text', isCheck: true },
		{ title: '员工体检', key: 'PersonMedicalsName', type: 'text', isCheck: true },
		{ title: '员工履历', key: 'PersonResumesName', type: 'text', isCheck: true },
		{ title: '员工合同', key: 'PersonContractsName', type: 'text', isCheck: true },
	],
	// 配置项（必传）
	config: {
		total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: props.isDisabled, // 是否显示表格操作栏
	},
});
// 初始化表格数据
const getTableData = async () => {
	try {
		await tableRef.value.doSearch(api().search, searchData.value);
	} catch (error) {
		other.setFormError(ci, error);
	}
};
const OnCreateClick = () => {
	other.openDialog(ci.proxy.$t('message._system.common.vm.add'), CreateDialog, null, getTableData);
};

const OnEditRowClick = (row: ISysPersonRepairBillView) => {
	other.openDialog(ci.proxy.$t('message._system.common.vm.edit'), EditDialog, row, getTableData);
};

const OnDetailsRowClick = (row: ISysPersonRepairBillView) => {
	other.openDialog(ci.proxy.$t('message._system.common.vm.detail'), DetailsDialog, row, getTableData);
};

// 删除
const onDelete = (row: ISysPersonRepairBillView) => {
	const ids = [row.ID] as (string | number)[];
	api()
		.delete(ids)
		.then(() => {
			getTableData();
		});
};

//批量删除
const onBatchDelete = async () => {
	const selectedRows = tableRef.value?.getSelectedRows();
	const selectedIds = selectedRows?.map((x: ISysPersonRepairBillView) => x.ID) as (string | number)[];
	if (selectedIds && selectedIds.length > 0) {
		try {
			await api().delete(selectedIds);
			// 先清除选择状态
			tableRef.value?.clearSelection();
			// 再重新获取数据
			await getTableData();
		} catch (error) {
			ElMessage.error(ci.proxy.$t('message._system.common.vm.error'));
		}
	} else {
		ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
	}
};

// 更新流程状态
const onUpdateWorkflowStatus = async () => {
	const selectedRows = tableRef.value?.getSelectedRows();
	const selectedIds = selectedRows?.map((x: ISysPersonRepairBillView) => x.ID) as (string | number)[];

	if (selectedIds && selectedIds.length > 0) {
		loading.value = true;
		try {
			const response = await api().updateWorkflowStatus(selectedIds);
			// 兼容大小写格式
			const code = response.Code || response.code;
			const message = response.Message || response.message;

			if (code === 200) {
				ElMessage.success(String(message) || '批量更新流程状态成功');
				// 只有成功时才清除选择和刷新数据
				tableRef.value?.clearSelection();
				await getTableData();
			} else if (code === 1) {
				ElMessage.error(String(message) || '批量更新流程状态失败');
				// 失败时不执行后续操作
			} else {
				// 处理其他状态码
				ElMessage.error(String(message) || '操作失败');
			}
		} catch (error) {
			console.error('更新流程状态出错:', error);
			ElMessage.error('批量更新流程状态失败');
		} finally {
			loading.value = false;
		}
	} else {
		ElMessage.error(ci.proxy?.$t('message._system.common.vm.check') || '请选择要操作的数据');
	}
};
// 添加计算属性判断是否有选中行
const hasSelectedRows = computed(() => {
	const selectedRows = tableRef.value?.getSelectedRows() || [];
	return selectedRows.length > 0;
});

const OnImportClick = () => {
	other.openDialog(ci.proxy.$t('message._system.common.vm.import'), ImportDialog, null, getTableData);
};

const onExport = () => {
	const selected = tableRef.value.getSelectedRows();
	if (selected.length > 0) {
		api().exportById(selected.map((x: any) => x.ID));
	} else {
		api().export({});
	}
};

// 页面加载时
onMounted(() => {
	loading.value = true;
	const promises: Promise<any>[] = [getTableData()];
	Promise.allSettled(promises).finally(() => {
		loading.value = false;
	});
});
</script>

<style lang="scss" scoped>
.range-input-container {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;

	.range-input-start,
	.range-input-end {
		flex: 1;
		min-width: 0;

		:deep(.el-input-number) {
			width: 100%;
		}

		:deep(.el-input__wrapper) {
			border-radius: 6px;
			box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
			transition: all 0.3s ease;

			&:hover {
				box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
			}

			&.is-focus {
				box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
			}
		}

		:deep(.el-input__inner) {
			font-size: 14px;
			color: var(--el-text-color-primary);
		}

		:deep(.el-input-number__decrease),
		:deep(.el-input-number__increase) {
			border: none;
			background: var(--el-fill-color-light);
			color: var(--el-text-color-regular);
			transition: all 0.2s ease;

			&:hover {
				background: var(--el-color-primary-light-9);
				color: var(--el-color-primary);
			}
		}
	}

	.range-separator {
		font-size: 14px;
		color: var(--el-text-color-regular);
		font-weight: 500;
		padding: 0 4px;
		user-select: none;
		white-space: nowrap;
	}
}

// 响应式优化
@media (max-width: 768px) {
	.range-input-container {
		flex-direction: column;
		gap: 8px;

		.range-input-start,
		.range-input-end {
			width: 100%;
		}

		.range-separator {
			transform: rotate(90deg);
			margin: 4px 0;
		}
	}
}
</style>
